<template>
  <div>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.row.cartId }}
        </template>
      </el-table-column>
      <el-table-column label="价格(单价)">
        <template slot-scope="scope">
          {{ scope.row.goodsCharacterList[0].goodsList[0].goodsPrice}}
        </template>
      </el-table-column>
      <el-table-column label="商品" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.goodsCharacterList[0].goodsList[0].goodsName}}：{{ scope.row.goodsCharacterList[0].characterName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="图片" width="210" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.goodsCharacterList[0].goodsList[0].goodsImg}}</span>
        </template>
      </el-table-column>
      <el-table-column label="总价" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.cartPrice}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column align="center" prop="created_at" label="Display_time" width="200">-->
<!--        <template slot-scope="scope">-->
<!--          <i class="el-icon-time" />-->
<!--          <span>{{ scope.row.usersList[0].createTime }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->

      <!--未实现-->
<!--      <el-table-column label="操作(暂无操作)"  align="center" width="200px">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button type="primary" round @click="dialogFormVisiblePutId(scope.$index)">修改</el-button>-->
<!--          <el-button type="danger" icon="el-icon-delete" circle @click="orderDel(scope.row.orderId)"> </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <el-pagination
      @current-change="handleCurrentChange"
      :page-size="5"
      background
      layout="prev, pager, next"
      :total="count">
    </el-pagination>
  </div>
  </div>
</template>

<script>
// import { getList } from '@/api/table'
import { cartList,cartCount,pagingList } from '@/api/server-cart'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      count: 30, //数据总条数
    }
  },
  created() {
    this.fetchData()
  },
  methods: {

    //分页
    handleCurrentChange(val) {
      var that = this
      pagingList(val,function(msg) {
        that.list = msg.data;
        if (msg.msg === '查询情况') {
          that.listLoading = false
        }
      })
    },


    fetchData() {
      var that = this
      that.listLoading = true
      cartList(function(msg) {
        that.list = msg.data;
        console.log(that.list);
        if (msg.msg === '查询情况') {
          that.listLoading = false
        }
      })

      //分页，数据总条数
      cartCount(function(msg) {
        console.log(msg.data.data)
        that.count = msg.data.data;

      })



      // this.listLoading = true
      // getList().then(response => {
      //   this.list = response.data.items
      //   this.listLoading = false
      // })
    }
  }
}
</script>
